﻿

namespace Unity.Game.ElisAdvance.ElisScript
{
    //玩家elis引入事件
    public class ElisState_Damage
    {
        public static void onProc(ElisActiveObject activeObject)
        {

            if (activeObject.getStateVector(0) == 1.0f)
            {
                float minDistance = activeObject.getVar("GLOBAL_DamageMinBloodTime").get_vector(0);
                if (activeObject.getStateTimer() > minDistance && activeObject.getFloorDistance() < 1.0f)
                {
                    if (activeObject.isLand())
                    {
                        activeObject.clearStateVector();
                        activeObject.setState(State.STATE_STAND);
                        activeObject.sendInvincibleTime(0.5f);
                    }

                    return;
                }

            }

        }

        public static void onEndState(ElisActiveObject obj, State state)
        {
            if (state != State.STATE_DAMAGE)
            {
                obj.sendInvincibleTime(0.5f);
            }

        }

        public static void onSetState(ElisActiveObject activeObject)
        {
            activeObject.getGravityEvent().setEnable(false);
            activeObject.getVar("GLOBAL_horiztantlKey").clear_vector();
            activeObject.getGravityEvent().refreshGravity();

            if (activeObject.getStateVector(0) == 1.0f)
            {
                activeObject.getAniManager().setAni("Damage1");
                activeObject.getAttackInfo().setEnable(false);

                float pushX = activeObject.getStateVector(1);
                float pushY = activeObject.getStateVector(2);
                float dir = activeObject.getStateVector(3);
                float minBloodTime = activeObject.getStateVector(4);

                activeObject.setDirection(Com.numToDirection(dir));
                activeObject.setXVelocity(Dir.getDirectionVar(activeObject.getDirection(), -pushX));
                activeObject.setYVelocity(pushY);
                activeObject.sendInvincible(true);

                activeObject.getVar("GLOBAL_DamageMinBloodTime").clear_vector();
                activeObject.getVar("GLOBAL_DamageMinBloodTime").push_vector(minBloodTime);


            }
            //Debug.Log(activeObject.getStateVector(0));
        }
    }
}